
/// @file Execution Client API provides the functionality for a Process to report its state to the Execution Management.
#ifndef NOSAL_EXEC_EXECUTION_CLIENT_H_
#define NOSAL_EXEC_EXECUTION_CLIENT_H_

#include "nosal/core/result.h"

#include <cstdint>

namespace netaos {
namespace nosal {
namespace exec {

///
/// @brief Defines the internal states of a Process
///
enum class ExecutionState : uint8_t
{
    ///
    /// @brief After a Process has been started by Execution Management, it reports ExecutionState kRunning
    ///
    kInitializing = 0,
    kRunning = 1,
    kTerminating = 2,
};

///
/// @brief Defines the status of EM's response to the ExecutionClient
///        after a ReportExecutionState call has been processed by EM
///
/// @note Implementation detail
///
enum class ExecutionStateResponseStatus : std::uint8_t
{
    kSuccess = 0,
    kInvalidTransition = 1,
    kInvalidReport = 2,
    kReportNotAllowed = 3
};

///
/// @brief Class to implement operations on Execution Client.
///
class ExecutionClient final
{

public:
    ///
    /// @brief Constructor that creates the Execution Client.
    ///
    ExecutionClient() noexcept;

    ///
    /// @brief Destructor of the Execution Client instance.
    ///
    ~ExecutionClient() noexcept;

    ///
    /// @brief Interface for a Process to report its internal state to Execution Management.
    ///
    /// @param state Value of the Execution State
    /// @returns An instance of netaos::nosal::core::Result. The instance holds an ErrorCode containing either one of the
    ///          specified errors or a void-value.
    ///
    /// @error netaos::nosal::exec::ExecErrc::kGeneralError if some unspecified error occurred
    /// @error netaos::nosal::exec::ExecErrc::kCommunicationError Communication error between Application and Execution
    ///        Management, e.g. unable to report state for Non-reporting Process.
    /// @error netaos::nosal::exec::ExecErrc::kInvalidTransition Invalid transition request (e.g. to Running when already in
    /// Running state)
    ///
    netaos::nosal::core::Result<void> ReportExecutionState(ExecutionState state) const noexcept;
};

}  // namespace exec
}  // namespace nosal
}  // namespace netaos

#endif  // NOSAL_EXEC_EXECUTION_CLIENT_H_
